﻿using System;
using System.Activities;
using System.Linq.Expressions;

namespace WFT.Activities
{
    /// <summary>
    /// Execute an expression with result of type Result and with the activity context in parameter
    /// </summary>
    /// <typeparam name="Result">Result of the expresssion</typeparam>
    public class ExpressionWithResultActivity<Result> : CodeActivity<Result>
    {
        public ExpressionWithResultActivity()
        {

        }

        public ExpressionWithResultActivity(Expression<Func<ActivityContext, Result>> expression)
        {
            Expression = expression;
        }

        public Expression<Func<ActivityContext, Result>> Expression { get; set; }

        protected override Result Execute(CodeActivityContext context)
        {
            return Expression.Compile()(context);
        }
    }
}
